<html>
<head>

	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    	<title>Question</title>

    	<link rel="stylesheet" type="text/css" href="style.css"/>

	<style type="text/css">
		.quiz { float:left; }
		.submit {float: right; margin-left: 10%}
		.set_rgt { margin-left: 27%; }
		#mycounter {float:right; margin-right: 55%}
	</style>

<script type = "text/javascript">

function timeLoop() {
	i--;
	if (i < 0) {
		m--;
		if(m >= 0) {
			i = 60;
			onTimer();
		}
	}
	
	else {
		setTimeout(onTimer, 1000);
	}
}

i = 60;
m = 4;
function onTimer() {
	
	
		if (i < 10 && i > -1) {
			document.getElementById('mycounter').innerHTML =  ('<h1>' + m + ':' + '0' + i + '</h1>');		
			timeLoop();
		}
		else if(m == 0 && i == 0) {
		document.getElementById('mycounter').innerHTML =  ('<h1>dude</h1>');		
		}
		else {
			document.getElementById('mycounter').innerHTML = ('<h1>' + m + ':' + i + '</h1>');
			timeLoop();
		}
	
}

</script>

<?php

include("function.php");
extract($_POST);

$qstat = startQuiz($class_uid, $quiz_uid);

$url = "http://146.95.30.80:9998/quiz/$quiz_uid";

$result = curl_Get($url);	
$r_a = json_decode($result, true);

$question = $r_a["question"];
$topic = $r_a["topic"];

amend();

$result = curl_Get($url);
$r_a = json_decode($result, true);

$set = 0;

foreach($r_a as $key => $val){
	foreach($val as $k => $v){
	        if($k == "choice_uid") {
	                $current = $v;
	                if($current >= $set) {
	                        $set = $v;
	                }
	        }
	        else if ($k == "description") {
	                $descrip[$current] = $v;
	        }
	}
	
}

?>

</head>
<body>

	<div id="container">
		<?php
			/*******Header*******/
			include("header.php");
		?>	

	 <div id="wrapper">
	  <div id="set_rgt">
            <div id="content">
<div id = "mycounter"><script type = "text/javascript">onTimer();</script></div>                      
		<h2>Question</h2>
		<? echo "<h3>$qstat</h3>"; ?>
		<?php
			print "<h2>Topic: $topic</h2>";
			print "<h2>$question</h2>";
			print "</br>";
		?>
		
		<form action="qanswer.php" method="post">
		<table>
		
		<?
			//$letter = "A";
			for($i = ($set -4) + 1; $i <= $set; $i++) {
        			 $choice = $descrip[$i];
        			 print "<tr><td><input type='radio' name='answer' value=$choice>$choice</td></tr>";
        			 //$letter++; 
			}
		?>

	<input type="hidden" name="student_uid" value='<?=$student_uid;?>' />
	<input type="hidden" name="class_uid" value='<?=$class_uid;?>' />
	<input type="hidden" name="quiz_uid" value='<?=$quiz_uid;?>' />	
		<tr><td></br></br></td><td></td></tr>
		<tr>
			<td>
			</td><td></td><td></td>

			<td class = "submit">
				<input class = "submit" type = "submit" value = "Submit" />
			</td>

		</tr>

		</table>
		</form>
		

</div>
	</div>
	</div>

		<?php
			/***Side Navigation***/
			include("sidebar.php");

			/****Extra Content***/
			include("extra.php");

			/*******Footer*******/
			include("footer.php"); 
		?>
	</div>

</body>
</html>
